package com.zzg.srb.core.controller.admin;

import com.zzg.srb.common.result.R;
import com.zzg.srb.core.entity.pojo.BorrowInfo;
import com.zzg.srb.core.entity.vo.BorrowInfoApprovalVo;
import com.zzg.srb.core.service.BorrowInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author zhengzg
 * @Date 2022/8/15 18:45
 * @Version 1.0
 */
@Api(tags = "借款管理")
@RestController
@RequestMapping("/admin/core/borrowInfo")
public class AdminBorrowInfoController {

    private Logger log = LoggerFactory.getLogger(AdminBorrowInfoController.class);

    @Resource
    private BorrowInfoService borrowInfoService;

    @ApiOperation("借款信息列表")
    @GetMapping("/list")
    public R list(){
        List<BorrowInfo> borrowInfos = borrowInfoService.selectList();
        return R.ok().data(borrowInfos);
    }

    @ApiOperation("借款信息详情")
    @ApiImplicitParam(value = "借款人id",required = true)
    @GetMapping("/show/{id}")
    public R show(@PathVariable Long id){
        log.info("借款信息详情 ===========》 AdminBorrowInfoController.show: " + id);
        return R.ok().data(borrowInfoService.getBorrowInfoDetail(id));
    }

    @ApiOperation("审批借款信息")
    @PostMapping("/approval")
    public R approvel(@RequestBody BorrowInfoApprovalVo borrowInfoApprovalVo){
        log.info("审批借款信息 =================》 AdminBorrowInfoController.approvel: " + borrowInfoApprovalVo);
        borrowInfoService.approval(borrowInfoApprovalVo);
        return R.ok().message("审批完成");
    }
}
